import React, { Component} from 'react';

import {get_localcity} from '../../api/index'
import {NavLink} from "react-router-dom"

class Local_d extends Component {
    constructor(){
        super()
        this.state={
            city_name:'',
            city_id:''
        }
    }
    componentDidMount(){
        get_localcity()
        .then(res=>{
            this.setState({
                city_name:res.data.name,
                city_id:res.data.id
            })
        })
    }
    render() {
        let city_name,city_id
        if(!this.state.city_name){
            city_name=null
        }else{
            city_name=this.state.city_name
            city_id=this.state.city_id
        }

      return (
        <div className='local_d'>
            <h4>
                <span>当前定位城市：</span>
                <span>定位不准确，请在城市列表中选择</span>
            </h4>
            <p>
                <NavLink to={'/city/'+city_id}>
                    <span className='local_city'>{city_name}</span>
                    <span className='iconfont icon-next_icon'></span>
                </NavLink>
            </p>
        </div>
      );
    }
  }
  export default Local_d